var timer;
function countdown(){
	var self = $('.product-info-panel-desc .time'),
	starttime = self.attr('starttime'),
	endtime = self.attr('endtime');
	
	var nowtime = new Date().getTime();
	starttime = new Date(starttime).getTime();
	endtime = new Date(endtime).getTime();
	overtime = endtime - nowtime;
	//alert("endtime:"+endtime + " overtime:"+overtime);
	if (starttime > nowtime) {
		starttime = new Date(starttime);
		month = starttime.getMonth()+1;
		day = starttime.getDate();		
		hour = starttime.getHours();
		self.html('开始时间：' + month + ' 月 ' + day + ' 日 ' + hour + ' 点');
		$('.product-info-panel-desc .red-addon').text('即将开始');
	} else if (overtime > 0) {
		seconds = overtime/1000;
        minutes = Math.floor(seconds/60);
        hours = Math.floor(minutes/60);
        days = Math.floor(hours/24);
        
        r_minute = minutes % 60;
        r_hours = hours % 24;		
      
		self.html('距离结束仅剩：<em class="num">' + days + '</em>天<em class="num">' + r_hours + '</em>时<em class="num"> '+ r_minute + '</em>分');
		$('.product-info-panel-desc .red-addon').text('正在进行');
	} else {
		self.html('已结束');
		$('.product-info-panel-desc .red-addon').text('已经结束');
	}
	
	timer = setTimeout("countdown()", 1000);
}

$(function(){
	$('.product-img-thumbs li').hover(function(){
		$('.product-img-thumbs li').removeClass('selected');
		$(this).addClass('selected');
		src = $(this).find('img').attr('src');
		$('.product-img-curr img').attr('src', src);
		$('.product-img-curr img').attr('jqimg', src);
	});
	
	$(".jqzoom").jqueryzoom({
		xzoom : 300,
		yzoom : 300,
		offset : 5,
		position : "right",
		lens : 1,
		preload : 1
	});
	
	$('.tab-bar li a').click(function(){
		self = $(this);
		self.closest('ul').find('a').removeClass('selected');
		self.addClass('selected');
		panel = self.attr('href');
		$('.tab-panel').removeClass('active');
		$(panel).addClass('active');
		event.preventDefault();
		return;
	});
	
	var bondlogs_pageno = 1, bondlogs = $('.bondlogs .bd'), bondlogs_page = $('.bondlogs .page');
	
	function getBondlogs(){
		url = bondlogs_page.attr('data-url');
		paramsters = {p: bondlogs_pageno};
		bondlogs.html('');
		bondlogs_page.html('');
		$.get(url, paramsters, function(data){
			bondlogs_page.append(data.pages);			
			$.each(data.results, function(i, item){
				htmlstring = '<li>';
				htmlstring += '<span>'+item.status_text+'</span>';
				htmlstring += '<span>￥'+item.price+'</span>';
				htmlstring += '<span>'+item.nickname+'</span>';
				htmlstring += '<span>'+item.format_time+'</span>';
				htmlstring += '</li>';				
				bondlogs.append(htmlstring);
			});
		},"json");	
	}
	
	$(document).delegate(".bondlogs .page a", "click", function(){
		
		self = $(this);
		bondlogs_pageno = self.attr('data-page');
		getBondlogs();
	});
	
	getBondlogs();
	
	countdown();
});